package com.blb.community.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.community.Utils.ListByStreamToTree;
import com.blb.community.mapper.ZyRoomMapper;
import com.blb.community.pojo.ZyRoom;
import com.blb.community.pojo.fourMenu.FourMenu;
import com.blb.community.service.IZyRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

@Service
public class ZyRoomServiceImpl extends ServiceImpl<ZyRoomMapper, ZyRoom> implements IZyRoomService {

    @Autowired
    private ZyRoomMapper zyRoomMapper;


    @Override
    public List<FourMenu> getFourMenu() {
        List<ZyRoom> zyRooms = zyRoomMapper.selectZyRoomByAllName();
        List<FourMenu> lists = new ArrayList<>();
        HashSet<FourMenu> set = new HashSet<>();
        for (ZyRoom one : zyRooms) {
            FourMenu fourMenu = new FourMenu(one.getCommunityId(), one.getCommunityName(), 0L, null);
            if (!set.contains(fourMenu)) {
                set.add(fourMenu);
                lists.add(fourMenu);
            }
            FourMenu fourMenu1 = new FourMenu(one.getBuildingId(), one.getBuildingName(), one.getCommunityId(), null);
            if (!set.contains(fourMenu1)) {
                set.add(fourMenu1);
                lists.add(fourMenu1);
            }
            FourMenu fourMenu2 = new FourMenu(one.getUnitId(), one.getUnitName(), one.getBuildingId(), null);
            if (!set.contains(fourMenu2)) {
                set.add(fourMenu2);
                lists.add(fourMenu2);
            }
            FourMenu fourMenu3 = new FourMenu(one.getRoomId(), one.getRoomName(), one.getUnitId(), null);
            if (!set.contains(fourMenu3)) {
                set.add(fourMenu3);
                lists.add(fourMenu3);
            }
        }
        return ListByStreamToTree.FourMenuTree(lists);
    }
}
